Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-8877] - Refactor VPC Create to use react-hook-form #11357

Merged
merged 17 commits into from
Dec 11, 2024

Conversation

coliu-akamai
Copy link
Contributor

@coliu-akamai coliu-akamai commented Dec 3, 2024

Description 📝

  • Use react-hook-form for VPC Create

Changes 🔄

  • Switched VPC create forms to react-hook-form and cleaned up accordingly
  • update VPC create unit tests

Target release date 🗓️

n/a

How to test 🧪

  • confirm behavior matches prod
    • error validation + scrolling into error
    • subnet recommendations + # of IPs
  • confirm tests pass:
yarn test VPCCreate
yarn cy:run -s "cypress/e2e/core/vpc/vpc-create.spec.ts"
yarn cy:run -s "cypress/e2e/core/linodes/create-linode-with-vpc.spec.ts"
Author Checklists

As an Author, to speed up the review process, I considered 🤔

👀 Doing a self review
❔ Our contribution guidelines
🤏 Splitting feature into small PRs
➕ Adding a changeset
🧪 Providing/improving test coverage
🔐 Removing all sensitive information from the code and PR description
🚩 Using a feature flag to protect the release
👣 Providing comprehensive reproduction steps
📑 Providing or updating our documentation
🕛 Scheduling a pair reviewing session
📱 Providing mobile support
♿ Providing accessibility support


  • I have read and considered all applicable items listed above.

As an Author, before moving this PR from Draft to Open, I confirmed ✅

  • All unit tests are passing
  • TypeScript compilation succeeded without errors
  • Code passes all linting rules

@coliu-akamai coliu-akamai added Work in Progress VPC Relating to VPC project labels Dec 3, 2024
@coliu-akamai coliu-akamai self-assigned this Dec 3, 2024
@coliu-akamai coliu-akamai changed the title Refactor vpc create refactor: [M3-8877] - Refactor VPC Create to use react-hook-form Dec 3, 2024
Comment on lines +79 to +81
form.setError('root.subnetLabel', { message: error.reason });
} else if (error?.field === 'subnets.ipv4') {
form.setError('root.subnetIPv4', { message: error.reason });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API returns subnet general errors as subnet.label or subnet.ipv4. Just setting form.setError(error?.field ...) for this leads to type errors when accessing the formstate's errors, so now using root.xxx. I think doing this is inline with react-hook-form's docs tho! - "you can set a server or global error with root as the key"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. Handling API errors like this is hard and I think you did the best we could here.

I was thinking maybe we could use errors.subnets?.root?.message but maybe not because we need to separate states for label and ipv4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a type error for form.setError('subnets.root', {...}} (but not when using errors.subnets?.root?.message, which I'm a bit confused about 😅)...

I think you're right though, errors.subnets?.root?.message wouldn't help with getting the two separate errors to show up at the same time - I ran into that issue when trying form.setError('subnets', {...}} and errors.subnets?.message. Ended up going with root.xxx

image


React.useEffect(() => {
if (!isEmpty(errors) && submitCount > previousSubmitCount.current) {
scrollErrorIntoView(undefined, { behavior: 'smooth' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble with getting the error to scroll for scrollErrorIntoViewV2, so switching back to scrollErrorIntoView for now. Gonna continue poking at it, but putting this up for review since everything else should be ready

Comment on lines 74 to 75
const ipValidationErrorMessage1 =
'A subnet must have either IPv4 or IPv6, or both, but not neither.';
Copy link
Contributor Author

@coliu-akamai coliu-akamai Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error now surfaces bc of how the VPC's validation schema is set up. However, wondering if it's better to match the original erroring behavior, especially since we don't support ipv6 in VPCs currently - ?

update: adding a temporary IPv4 required message (+ todo comments to change back when IPv6 is supported) to hide mention of IPv6, since we don't show any IPv6 field/IPv6 related stuff when creating a VPC (felt like it could be confusing that we mention ipv6s)

@coliu-akamai coliu-akamai marked this pull request as ready for review December 9, 2024 21:15
@coliu-akamai coliu-akamai requested review from a team as code owners December 9, 2024 21:15
@coliu-akamai coliu-akamai requested review from jdamore-linode, bnussman-akamai and cpathipa and removed request for a team December 9, 2024 21:15
Copy link

github-actions bot commented Dec 9, 2024

Coverage Report:
Base Coverage: 86.9%
Current Coverage: 86.78%

Copy link
Member

@bnussman-akamai bnussman-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome so far! I love refactors like this 🧹

@coliu-akamai coliu-akamai added Add'tl Approval Needed Waiting on another approval! and removed Ready for Review labels Dec 10, 2024
Copy link
Contributor

@cpathipa cpathipa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! @coliu-akamai!
confirming the verification steps around create VPC flow.

@bnussman-akamai bnussman-akamai added Approved Multiple approvals and ready to merge! and removed Add'tl Approval Needed Waiting on another approval! labels Dec 11, 2024
@linode-gh-bot
Copy link
Collaborator

Cloud Manager UI test results

🔺 1 failing test on test run #14 ↗︎

❌ Failing✅ Passing↪️ Skipped🕐 Duration
1 Failing465 Passing2 Skipped100m 5s

Details

Failing Tests
SpecTest
smoke-billing-activity.spec.tsBilling Activity Feed » displays correct timezone for invoice and payment dates

Troubleshooting

Use this command to re-run the failing tests:

yarn cy:run -s "cypress/e2e/core/billing/smoke-billing-activity.spec.ts"

@coliu-akamai
Copy link
Contributor Author

merging - failing test fixed in dev (thanks Banks!)

@coliu-akamai coliu-akamai merged commit cca950f into linode:develop Dec 11, 2024
22 of 23 checks passed
Copy link

cypress bot commented Dec 11, 2024

Cloud Manager E2E    Run #6955

Run Properties:  status check failed Failed #6955  •  git commit cca950fbe6: refactor: [M3-8877] - Refactor VPC Create to use `react-hook-form` (#11357)
Project Cloud Manager E2E
Branch Review develop
Run status status check failed Failed #6955
Run duration 35m 51s
Commit git commit cca950fbe6: refactor: [M3-8877] - Refactor VPC Create to use `react-hook-form` (#11357)
Committer Connie Liu
View all properties for this run ↗︎

Test results
Tests that failed  Failures 3
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 2
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 466
View all changes introduced in this branch ↗︎

Tests for review

Failed  clone-linode.spec.ts • 1 failed test

View Output Video

Test Artifacts
clone linode > can clone a Linode from Linode details page Screenshots Video
Failed  rebuild-linode.spec.ts • 2 failed tests

View Output Video

Test Artifacts
rebuild linode > rebuilds a linode from Community StackScript Screenshots Video
rebuild linode > rebuilds a linode from Account StackScript Screenshots Video
Flakiness  switch-linode-state.spec.ts • 2 flaky tests

View Output Video

Test Artifacts
switch linode state > powers on a linode from landing page Screenshots Video
switch linode state > reboots a linode from landing page Screenshots Video
Flakiness  create-linode.spec.ts • 1 flaky test

View Output Video

Test Artifacts
... > creates a Dedicated CPU Linode Screenshots Video

@coliu-akamai coliu-akamai deleted the refactor-vpc-create branch December 11, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge! VPC Relating to VPC project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants